#include <stdio.h>
#include <algorithm>
#include <iostream>
using namespace std;
// 站队问题

void getMaxL(int *arr, int *p, int n)
{
    p[0] = 1;
    for (int i = 1; i < n; i++)
    {
        p[i] = 1;
        for (int j = 0; j < i; j++)
        {
            if (arr[i] > arr[j] && p[i] < p[j] + 1)
            {
                p[i] = p[j] + 1;
            }
        }
    }
}

void getMaxR(int *arr, int *p, int n)
{
    p[n - 1] = 1;
    for (int i = n - 2; i >= 0; i--)
    {
        p[i] = 1;
        for (int j = n - 1; j > i; j--)
        {
            if (arr[i] > arr[j] && p[i] < p[j] + 1)
            {
                p[i] = p[j] + 1;
            }
        }
    }
}

int main()
{
    int n;
    int arr[10000];
    int p1[10000];
    int p2[10000];
    while (scanf("%d", &n) != EOF)
    {
        for (int i = 0; i < n; i++)
            scanf("%d", &arr[i]);

        getMaxL(arr, p1, n);
        getMaxR(arr, p2, n);
        for (int i = 0; i < n; i++)
            p1[i] += p2[i];
        for (int i = 0; i < n; i++)
            p1[0] = p1[0] > p1[i] ? p1[0] : p1[i];
        printf("%d\n", n - p1[0] + 1);
    }
    return 0;
}